home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / midas060 / samples / midpnt / midpmida.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-25  |  5.7 KB  |  233 lines

  1. /*
  2.  *      MidpMIDAS.cpp
  3.  *
  4.  * MIDAS Module Player for Windows NT MIDAS interface module
  5.  *
  6.  * $Id: MidpMIDAS.cpp 1.7 1997/01/25 13:17:44 pekangas Exp $
  7.  *
  8.  * Copyright 1996 Petteri Kangaslampi
  9. */
  10.  
  11. #define WIN32_LEAN_AND_MEAN
  12. #include <windows.h>
  13. #include <mmsystem.h>
  14. #include <ddeml.h>
  15. #include <process.h>
  16. #include <stdio.h>
  17. #include "midasdll.h"
  18. #include "MidpNT.h"
  19.  
  20. #define POLLRATE 50
  21.  
  22. int             mixRate = 44100, stereo = 1, force8bit = 0;
  23. static volatile int backgroundPlay = 0;
  24.  
  25.  
  26.  
  27.  
  28. /****************************************************************************\
  29. *
  30. * Function:     void MIDASerror(void)
  31. *
  32. * Description:  Gets the last MIDAS error, displays it, and exits
  33. *
  34. \****************************************************************************/
  35.  
  36. void MIDASerror(void)
  37. {
  38.     char        *errorMessage;
  39.  
  40.     errorMessage = MIDASgetErrorMessage(MIDASgetLastError());
  41.     MessageBox(NULL, errorMessage, "MIDAS Error!",
  42.         MB_APPLMODAL | MB_ICONSTOP | MB_OK);
  43.     if ( ddeInit )
  44.         DdeUninitialize(ddeInstance);
  45.     MIDASclose();
  46.     ExitProcess(1);
  47.     while(1);                           // we should NEVER end up here
  48. }
  49.  
  50.  
  51.  
  52.  
  53. /****************************************************************************\
  54. *
  55. * Function:     void StopFreeModule(MIDASmodule module);
  56. *
  57. * Description:  Stops playing a module and deallocates it
  58. *
  59. * Input:        gmpModule *module       Pointer to module structure returned
  60. *                                       by LoadPlayModule().
  61. *
  62. \****************************************************************************/
  63.  
  64. void StopFreeModule(MIDASmodule module)
  65. {
  66.     if ( module == NULL )
  67.         return;
  68.  
  69.     AddTextLine("Stopping module");
  70.     if ( !MIDASstopModule(module) )
  71.         MIDASerror();
  72.  
  73.     AddTextLine("Deallocating module");
  74.     if ( !MIDASfreeModule(module) )
  75.         MIDASerror();
  76.  
  77.     SendMessage(mainWinHandle, WM_SETTEXT, 0,
  78.         (LPARAM) "MIDAS Module Player for Windows NT");
  79. }
  80.  
  81.  
  82.  
  83.  
  84. /****************************************************************************\
  85. *
  86. * Function:     MIDASmodule LoadModule(char *fileName);
  87. *
  88. * Description:  Loads a module file
  89. *
  90. * Input:        char *fileName          module file name
  91. *
  92. * Returns:      Pointer to gmpModule structure for the loaded module,
  93. *               NULL if loading failed.
  94. *
  95. \****************************************************************************/
  96.  
  97. MIDASmodule LoadModule(char *fileName)
  98. {
  99.     MIDASmodule module;
  100.     char        *errorMessage;
  101.  
  102.     AddTextLine("Loading Module");
  103.  
  104.     SendMessage(mainWinHandle, WM_SETTEXT, 0, (LPARAM) "MidpNT - Loading...");
  105.  
  106.     if ( (module = MIDASloadModule(fileName)) == NULL )
  107.     {
  108.         errorMessage = MIDASgetErrorMessage(MIDASgetLastError());
  109.         MessageBox(NULL, errorMessage, "Module load failure",
  110.             MB_APPLMODAL | MB_ICONSTOP | MB_OK);
  111.         return NULL;
  112.     }
  113.  
  114.     return module;
  115. }
  116.  
  117.  
  118.  
  119.  
  120. /****************************************************************************\
  121. *
  122. * Function:     void PlayModule(MIDASmodule module);
  123. *
  124. * Description:  Starts playing a module
  125. *
  126. * Input:        MIDASmodule module      the module
  127. *
  128. \****************************************************************************/
  129.  
  130. void PlayModule(MIDASmodule module)
  131. {
  132.     char        buf[64];
  133.     MIDASmoduleInfo moduleInfo;
  134.  
  135.     if ( !MIDASplayModule(module, 0) )
  136.         MIDASerror();
  137.  
  138.     if ( !MIDASgetModuleInfo(module, &moduleInfo) )
  139.         MIDASerror();
  140.  
  141.     sprintf(buf, "Playing \"%s\" - %i channels", moduleInfo.songName,
  142.         moduleInfo.numChannels);
  143.     AddTextLine(buf);
  144.  
  145.     sprintf(buf, "MidpNT - %s", moduleInfo.songName);
  146.     SendMessage(mainWinHandle, WM_SETTEXT, 0, (LPARAM) buf);
  147. }
  148.  
  149.  
  150.  
  151.  
  152. /****************************************************************************\
  153. *
  154. * Function:     void InitMIDAS(void)
  155. *
  156. * Description:  Initializes MIDAS Sound System
  157. *
  158. \****************************************************************************/
  159.  
  160. void InitMIDAS(void)
  161. {
  162.     AddTextLine("Initializing MIDAS Sound System");
  163.  
  164.     if ( !MIDASinit() )
  165.         MIDASerror();
  166.  
  167.     /* Start polling MIDAS in a thread: */
  168.     if ( !MIDASstartBackgroundPlay(POLLRATE) )
  169.         MIDASerror();
  170.  
  171.     backgroundPlay = 1;
  172. }
  173.  
  174.  
  175.  
  176.  
  177. /****************************************************************************\
  178. *
  179. * Function:     void CloseMIDAS(void)
  180. *
  181. * Description:  Uninitializes MIDAS Sound System
  182. *
  183. \****************************************************************************/
  184.  
  185. void CloseMIDAS(void)
  186. {
  187.     if ( backgroundPlay )
  188.         if ( !MIDASstopBackgroundPlay() )
  189.             MIDASerror();
  190.  
  191.     if ( !MIDASclose() )
  192.         MIDASerror();
  193. }
  194.  
  195.  
  196.  
  197.  
  198. /****************************************************************************\
  199. *
  200. * Function:     void StartupMIDAS(void)
  201. *
  202. * Description:  Start up interface to MIDAS Sound System
  203. *
  204. \****************************************************************************/
  205.  
  206. void StartupMIDAS(void)
  207. {
  208.     MIDASstartup();
  209. }
  210.  
  211.  
  212. /*
  213.  * $Log: MidpMIDAS.cpp $
  214.  * Revision 1.7  1997/01/25 13:17:44  pekangas
  215.  * Rewrote archive support
  216.  *
  217.  * Revision 1.6  1997/01/17 00:08:51  pekangas
  218.  * Now puts song name and loading/decompressing messages in main window
  219.  * caption
  220.  *
  221.  * Revision 1.5  1997/01/14 17:42:08  pekangas
  222.  * Changed to use MIDAS DLL API
  223.  *
  224.  * Revision 1.4  1996/08/13 20:22:15  pekangas
  225.  * #included stdio.h as MIDAS rawfile.h no longer does that
  226.  *
  227.  * Revision 1.3  1996/08/02  17:53:13  pekangas
  228.  * Fixed to compile with Watcom C again
  229.  *
  230.  * Revision 1.2  1996/07/16  19:19:37  pekangas
  231.  * Fixed to compile with Visual C, added RCS keywords, changed to LFs
  232.  *
  233. */